package com.zhss.redis.java;

import org.openjdk.jol.info.ClassLayout;

import java.util.stream.IntStream;


/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/9/29
 */
public class ObjectLock {
	private Integer amount = 0;

	public void increase() {
		IntStream.rangeClosed(1, 10).forEach(i->{
			synchronized (this) {
				amount++;
				String printable = ClassLayout.parseInstance(this).toPrintable();
				System.out.println(printable);
			}
		});
	}

	public void decrement() {
		IntStream.rangeClosed(1, 10).forEach(i->{
			synchronized (this) {
				amount--;
				String printable = ClassLayout.parseInstance(this).toPrintable();
				System.out.println(printable);
			}
		});
	}

	public static void main(String[] args) throws InterruptedException {
		ObjectLock objectLock = new ObjectLock();
//		String printable = ClassLayout.parseInstance(objectLock).toPrintable();
//		System.out.println(printable);
		objectLock.increase();
		new Thread(objectLock::increase).start();
		new Thread(objectLock::decrement).start();
		Thread.sleep(5000);
	}



}
